package com.yifeng.repo.base.service.impl;

import com.yifeng.base.bds.api.store.StoreLocationRestService;
import com.yifeng.base.bds.api.store.dto.StoreLocationInfoDto;
import com.yifeng.base.bds.api.store.params.StoreLocationInfoParam;
import com.yifeng.repo.base.params.ConsoleParam;
import com.yifeng.repo.base.security.proxy.CommonProxy;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by daibing on 2024/2/3.
 */
public class StoreLocationRestServiceImpl extends CommonProxy implements StoreLocationRestService {
    private final String mapping;

    public StoreLocationRestServiceImpl(ConsoleParam consoleParam) {
        super(consoleParam);
        this.mapping = "/yfcloud/bds/rest/StoreLocationRestService";
    }

    @Override
    public List<StoreLocationInfoDto> listLocationInfo(StoreLocationInfoParam param) {
        String url = consoleParam.getUrl() + mapping + "/listLocationInfo";
        Map<String, String> params = new HashMap<>(4);
        params.put("provinceCode", param.getProvinceCode());
        params.put("longitude", param.getLongitude() != null ? param.getLongitude().toString() : null);
        params.put("latitude", param.getLatitude() != null ? param.getLatitude().toString() : null);
        params.put("range", String.valueOf(param.getRange()));
        String queryParameters = buildQueryParameters(params);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreLocationInfoDto.class);
    }

}
